package org.yxj.bulletinlibaray;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import org.yxj.bulletinlib.BulletinAdapter;
import org.yxj.bulletinlib.BulletinView;
import org.yxj.bulletinlib.ItemBulletinClickListener;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    BulletinAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        BulletinView mBulletinView = findViewById(R.id.mBulletinView);
        List<String> list = new ArrayList<>();
        list.add("得福卡的");
        list.add("看来你没看到");
        mBulletinView.setAdapter(adapter = new BulletinAdapter<String>(list) {
            @Override
            protected int onLayoutId() {
                return R.layout.common_textview;
            }
            @Override
            protected void onBindItemView(View view, String s, int position) {
                TextView tv = view.findViewById(R.id.tv);
                view.setBackgroundColor((position%2==0)?Color.RED:Color.YELLOW);
                tv.setText(s);
            }
        });
        adapter.setItemBulletinClickListener(new ItemBulletinClickListener<String>() {
            @Override
            public void ItemBulletinClick(View view, String o) {
                Toast.makeText(MainActivity.this,o,Toast.LENGTH_LONG).show();
            }
        });
    }

}